﻿// <copyright file="EnumLayer.cs" company="City of Portland, BES-ASM">
// </copyright>
// <summary>EnumLayer class</summary>

namespace BESASM.EMGAATS.UI.ArcMap
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using ESRI.ArcGIS.Carto;

  /// <summary>
  /// A class implementing IEnumLayer for use in adding layers to the map.
  /// </summary>
  public class EnumLayer : List<ILayer>, IEnumLayer
  {
    private int currentIndex = -1;

    #region IEnumLayer Members
    /// <summary>
    /// Gets the next layer in the list.
    /// </summary>
    /// <returns>The next layer in the list or an exception when the last layer is reached.</returns>
    public ILayer Next()
    {
      if (this.currentIndex < this.Count - 1)
      {
        return this[++this.currentIndex];
      }
      else
      {
        // ArcObjects expects error, not null at end of enumeration.
        throw new System.Runtime.InteropServices.COMException("Index out of range.");
      }
    }

    /// <summary>
    /// Resets the enumerator
    /// </summary>
    public void Reset()
    {
      this.currentIndex = -1;
    }
    #endregion
  }
}
